package danny.hoi.service.export.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import danny.hoi.dao.export.system.DeptDao;
import danny.hoi.domain.export.system.Dept;
import danny.hoi.domain.export.system.DeptExample;
import danny.hoi.service.export.system.DeptService;
import danny.hoi.utils.UUUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptDao deptDao;

    @Override
    public List<Dept> findAll(DeptExample example) {
        return deptDao.selectByExample(example);
    }

    @Override
    public PageInfo<Dept> findByPages(DeptExample example, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Dept> depts = deptDao.selectByExample(example);

        return new PageInfo<>(depts);
    }

    @Override
    public Dept findById(String id) {
        return deptDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Dept dept) {
        dept.setDeptId(UUUIDUtil.getUuid());
        deptDao.insertSelective(dept);
    }

    @Override
    public void update(Dept dept) {
        deptDao.updateByPrimaryKeySelective(dept);
    }

    @Override
    public void delete(String id) {
        deptDao.deleteByPrimaryKey(id);
    }
}
